package com.ruoyi.security.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.MaintainOrder;
import com.ruoyi.security.service.IMaintainOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 业务计划Controller
 *
 * @author zmc
 * @date 2021-12-21
 */
@Api(tags = " 业务计划")
@RestController
@RequestMapping("/maintainOrder")
public class InspectionPlanController extends BaseController {
    @Autowired
    private IMaintainOrderService maintainOrderService;

    /**
     * 查询业务计划列表
     */
    @ApiOperation(value="查询业务计划列表", notes="查询业务计划列表")
    @PreAuthorize(hasPermi = "security:maintainOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(MaintainOrder maintainOrder) {
        startPage();
        List<MaintainOrder> list = maintainOrderService.selectMaintainOrderList(maintainOrder);
        return getDataTable(list);
    }

    /**
     * 远程接口查询业务计划列表
     */
    @ApiOperation(value="远程接口查询计划列表", notes="远程接口查询计划列表")
    @PostMapping("/listMO")
    public R<List<MaintainOrder>> listMO(MaintainOrder maintainOrder) {
        List<MaintainOrder> list = maintainOrderService.selectMaintainOrderList(maintainOrder);
        return R.ok(list);
    }


    /**
     * 导出业务计划列表
     */
    @ApiOperation(value="导出业务计划列表", notes="导出业务计划列表")
    @PreAuthorize(hasPermi = "security:maintainOrder:export")
    @Log(title = "业务计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintainOrder maintainOrder) throws IOException {
        List<MaintainOrder> list = maintainOrderService.selectMaintainOrderList(maintainOrder);
        ExcelUtil<MaintainOrder> util = new ExcelUtil<MaintainOrder>(MaintainOrder.class);
        util.exportExcel(response, list, "业务计划数据");
    }
    /**
     * 获取业务计划详细信息
     */
    @ApiOperation(value="获取业务计划详细信息", notes="获取业务计划详细信息")
    @PreAuthorize(hasPermi = "security:maintainOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(maintainOrderService.selectMaintainOrderById(id));
    }

    /**
     * 新增业务计划
     */
    @ApiOperation(value="新增业务计划", notes="新增业务计划")
    @PreAuthorize(hasPermi = "security:maintainOrder:add")
    @Log(title = "业务计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintainOrder maintainOrder) {
        return toAjax(maintainOrderService.insertMaintainOrder(maintainOrder));
    }

    /**
     * 修改业务计划
     */
    @ApiOperation(value="修改业务计划", notes="修改业务计划")
    @PreAuthorize(hasPermi = "security:maintainOrder:edit")
    @Log(title = "业务计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintainOrder maintainOrder) {
        return toAjax(maintainOrderService.updateMaintainOrder(maintainOrder));
    }

    /**
     * 删除业务计划
     */
    @ApiOperation(value="删除业务计划", notes="删除业务计划")
    @ApiImplicitParam(name = "ids", value = "业务计划ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:maintainOrder:remove")
    @Log(title = "业务计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(maintainOrderService.deleteMaintainOrderByIds(ids));
    }
}
